const Group = require("../model/group_model");

exports.getGroupsApi = async (_id) => {
  return await Group.find({
    $or: [
      { group_users: { $in: [_id] } },
      { group_creator: _id },
    ],
  });
};


exports.getGroupByNumberApi = async (group_number) => {
    return await Group.findOne({
        group_number
    })
}


exports.addGroupMemberApi = async (fromId,groupId) => {
    return await Group.updateOne({_id:groupId},{$addToSet:{
        group_users:fromId
    }})
}


exports.addGroupApi = async (group) => {
    return new Group({
        ...group
    }).save()
}